package fun.zhufn.oldcomm.model.bo.customlist;

import fun.zhufn.oldcomm.model.bo.Path;
import fun.zhufn.oldcomm.model.bo.json.JsonList;
import fun.zhufn.oldcomm.model.bo.json.JsonMap;

public class PathList extends CustomList<Path>{
    @Override
    public JsonList toJsonList() {
        var ret = new JsonList();
        for (var v: data) {
            var mp = new JsonMap();
            mp.put("code", v.getCode());
            mp.put("name", v.getName());
            mp.put("isInland", v.isInland());
            mp.put("isUp", v.isUp());
            mp.put("day", v.getDay());
            mp.put("time", v.getTime());
            mp.put("endTime", v.getEndTime());
            mp.put("note", v.getNote());
            mp.put("orders", v.getOrders());
            ret.add(mp);
        }
        return ret;
    }

    @Override
    public void fromJsonList(JsonList d) {
        if (d == null) return;
        data.clear();
        for (Object o: d) {
            try {
                JsonMap v = (JsonMap) o;
                data.add(new Path(
                        (String)v.get("code"),
                        (String)v.get("name"),
                        (Boolean)v.get("isInland"),
                        (Boolean) v.get("isUp"),
                        (int)v.get("day"),
                        (String)v.get("time"),
                        (String)v.get("note"),
                        v.get("endTime") == null?null:(Integer)v.get("endTime"),
                        v.get("orders") == null? null:(JsonList) v.get("orders")
                ));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
